/**
 * 初始化数据
 * @param {Object} type
 * @param {Object} id
 */
function initData(type,id){
	if(type=="update"){
		$("#b_url").val("/rest/BaseMonitorBusiness/modify");
		$$.ajax({
	        url:"/rest/BaseMonitorBusiness/query",
	        data : {
	            id : id
	        },
	        success : function(data){
	            $("#b_id").val(data.id);
	            $("#b_appCode").val(data.appCode);
	            $("#b_appName").val(data.appName);
	            $("#b_appUrl").val(data.appUrl);
	            $("#b_noticeUser").val(data.noticeUser);
	            var status = data.status;
	            if(status==1){
	            	$('#in-use').attr('checked', 'checked');
	            }else{
	            	$('#not-in-use').attr('checked', 'checked');
	            }
	            $("#b_remarks").val(data.remarks);
	        }
	    });
	}else{
		$("#b_url").val("/rest/BaseMonitorBusiness/add");
	}
}

/**
 * 校验表单
 */
function validForm(){
	return $("#monitorForm").valid();
}

/**
 * 添加表单校验
 */
function menuFormValid() {
    $("#monitorForm").validate({
        rules: {
            b_appCode: {
                required: true,
                rangelength: [1,30]
            },
            b_appName: {
                required: true,
                rangelength: [1,30]
            },
            b_appUrl: {
                required: true,
                rangelength: [1,100]
            },
            b_noticeUser: {
                rangelength: [1,30]
            },
            b_rowSort: {
                required: true,
                isPositiveInteger: true
            },
            b_remarks:{
                maxlength: 250
            }
        },
        errorPlacement: function(error, element) {
            error.appendTo(element.parent());
        },
        errorElement: "span",
        errorClass: "errortips",
        success: 'valid',
        messages: {
        	b_appCode: {
                required: "(必填)",
                rangelength:"(系统编码必须是{0}到{1}个字符)"
            },
            b_appName: {
                required: "(必填)",
                rangelength:"(系统名称必须是{0}到{1}个字符)"
            },
            b_appUrl: {
                required: "(必填)",
                rangelength:"(系统路径必须是{0}到{1}个字符)"
            },
            b_noticeUser: {
                rangelength:"(通知人必须是{0}到{1}个字符)"
            },
            b_rowSort: {
                required: "(必填)",
                isPositiveInteger:"(排序值必须是整数)"
            },
            b_remarks: {
                maxlength:"(备注不能超过250个字符)"
            }
        },
    });
}

/**
 * 执行数据保存
 */
function submitForm() {
	var validFormRes = false;
    $$.form({
    	fname:"#monitorForm",
        async:false,
        able:function(){
            validFormRes = false;
        },
        checkForm:validForm,
        success:function () {
            validFormRes = true;
        }
    });
    return validFormRes;
}

$(function(){
	$('#b_appCode').focus();
    menuFormValid();
})